﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PersonExpertChangeNaI.aspx.cs" Inherits="RN.ERP.Web.Person.PersonChangeNameID" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>姓名身份证号码变更</title>
    <link rel="Stylesheet" type="text/css" href="../Scripts/ligerUI/skins/Aqua/css/ligerui-all.css" />
    <link rel="Stylesheet" type="text/css" href="../Styles/skins/blue/css/style.css" />
    <link rel="Stylesheet" type="text/css" href="../Styles/skins/blue/css/style_msg.css" />
    <style type="text/css">
        .IE6png{behavior: url("js/iepngfix.htc");}
        #btnSend{padding: 5px 10px;background: rgb(255, 199, 56);margin-left: 10px;}
        .btnSend{padding: 5px 10px;background: rgb(255, 199, 56);margin-left: 10px;}
        #btnSend.disabled{background:lightgray;color:Gray;}
        .zhuyi_nr{ width:265px; border:1px #c1e17a solid; padding:10px; font-size:14px; background-color:#edf8d4; color:#597a0c; margin-left:100px;}
    </style>
</head>
<body>
    <form id="form2" runat="server">
    <input id="hidmobile" name="hidmobile" type="hidden" value="" runat="server"/>
    <div class="main_tt">
        <div class="main_tt_r_p15">
            <!--title_tt 开始-->
            <div class="title_tt">
                <div class="title_tt_l">
                    <img src="../images/tt_title_l.jpg" width="9" height="33" />
                    <img src="../images/xx_icon.jpg" width="24" height="33" />
                </div>
                <div class="title_tt_h">修改姓名与身份证号码</div>
                <div class="title_tt_r">
                    <img src="../images/tt_title_r.jpg" width="9" height="33" />
                </div>
            </div>
            <!--title_tt 结束-->

            <!--userinfo_tt 开始-->
            <div class="userinfo_tt">
                <div id="sendVerCodePage" style="display:none;">
                    <div class="xian">
                        <div class="about_title">发送验证码</div>
                    </div>
                    <div  class="userinfo_tt_left">
                        <ul>
                            <li>
                                <label>手机号</label>
                                <span class="input_l"><img src="../images/input_l.jpg" width="10" height="31" alt="" /></span>
                                <span class="input_mm"><input id="txtPhone" type="text" class="inp" maxlength="11" /></span>
                                <input type="button" id="btnSend" value="发送" />
                                <span class="input_r"><img src="../images/input_r.jpg" width="10" height="31" alt="" /></span>
                            </li>
                            <li>
                                <label>验证码</label>
                                <span class="input_l"><img src="../images/input_l.jpg" width="10" height="31" alt="" /></span>
                                <span class="input_mm"><input id="txtVerCode" type="text" class="inp" maxlength="6" /></span>
                                <span class="input_r"><img src="../images/input_r.jpg" width="10" height="31" alt="" /></span>
                            </li>
                            <li>
                                <label>&nbsp;</label>
                               <a id="btnToChangePwd" style="text-decoration:none;" href="###"> <span class="ckicon02">确认</span></a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div id="changeNaIPage" style="display:none;">
                    <div class="xian">
                        <div class="about_title">姓名与身份证号码</div>
                    </div>
                    <div class="userinfo_tt_left">
                        <ul>
                            <li>
                                <label>姓名</label>
                                <span class="input_l"><img src="../images/input_l.jpg" width="10" height="31" alt="" /></span>
                                <span class="input_mm"><input id="name" type="text" class="inp" disabled  /></span>
                                <span class="input_r"><img src="../images/input_r.jpg" width="10" height="31" alt="" /></span>
                                <input class="btnSend" type="button" id="edtname" value="修改" />
                            </li>
                            <li>
                                <label>身份证号码</label>
                                <span class="input_l"><img src="../images/input_l.jpg" width="10" height="31" alt="" /></span>
                                <span class="input_mm"><input id="idnum" type="text" class="inp" disabled /></span>
                                <span class="input_r"><img src="../images/input_r.jpg" width="10" height="31" alt="" /></span>
                                <input class="btnSend" type="button" id="edtid" value="修改" />
                            </li>
                            <li>
                                <div class="zhuyi_nr" style="width: 265px;">
                                    <font color="red">姓名和身份证号码只可修改一次 </font>
                                </div>
                            </li>
                            <li>
                                <label>&nbsp;</label>
                              <a id="btnChangNaI" style="text-decoration:none;" href="###">  <span class="ckicon02">修改</span></a>
                              <a id="btnBack" style="text-decoration:none;" href="../LoginExpert.aspx">  <span class="ckicon02">返回</span></a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="clear"></div>
            </div>
            <!--userinfo_tt 结束-->
        </div>
    </div>
    </form>

    <script src="../Scripts/jquery-1.7.min.js" type="text/javascript"></script>
    <script src="../Scripts/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
    <script title="common">
        var validitor = {
            //手机号
            phone: function (p) {
                return /^1[3-8]\d{9}$/.test(p);
            }
            , vercode: function (c) {
                return /^\d{6}$/.test(c);
            }
            , pwd: function (p) {
                var patrn = /^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{6,}$/;
                return !!patrn.exec(p);
            }
            , idcard: function (p) {
                var msg;
                return isIdCardNo(p, msg);
            }
        };
        function isIdCardNo(num, message) {
            num = num.toUpperCase();
            //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X。   
            if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) {
                message = '输入的身份证号长度不对，或者号码不符合规定！/n15位号码应全为数字，18位号码末位可以为数字或X。';
                return false;
            }
            //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。 
            //下面分别分析出生日期和校验位 
            var len, re;
            len = num.length;
            if (len == 15) {
                re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
                var arrSplit = num.match(re);

                //检查生日日期是否正确 
                var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
                var bGoodDay;
                bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
                if (!bGoodDay) {
                    //alert("输入的身份证号里出生日期不对!");
                    message = '输入的身份证号里出生日期不对！';
                    return false;
                }
                else {
                    //将15位身份证转成18位 
                    //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。 
                    var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
                    var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
                    var nTemp = 0, i;
                    num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);
                    for (i = 0; i < 17; i++) {
                        nTemp += num.substr(i, 1) * arrInt[i];
                    }
                    num += arrCh[nTemp % 11];
                    return num;
                }
            }
            if (len == 18) {
                re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
                var arrSplit = num.match(re);

                //检查生日日期是否正确 
                var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
                var bGoodDay;
                bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
                if (!bGoodDay) {

                    //alert("输入的身份证号里出生日期不对！");
                    message = '输入的身份证号里出生日期不对！';
                    return false;
                }
                else {
                    //检验18位身份证的校验码是否正确。 
                    //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。 
                    var valnum;
                    var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
                    var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
                    var nTemp = 0, i;
                    for (i = 0; i < 17; i++) {
                        nTemp += num.substr(i, 1) * arrInt[i];
                    }
                    valnum = arrCh[nTemp % 11];
                    if (valnum != num.substr(17, 1)) {
                        message = '18位身份证的校验码不正确！应该为：' + valnum;
                        return false;
                    }
                    return num;
                }
            }
            return false;
        }
    </script>
    <script type="text/javascript">
        var phoneNum, verCode, isLoading;

        //初始化操作
        var hashChange = function (h) {
            if (h) location.hash = h;

            var hash = location.hash;

            if (hash == "#sendVerCodePage" || hash == "") {
                $("#sendVerCodePage").show();
                $("#changeNaIPage").hide();
            } else if (hash == "#changeNaIPage") {
                $("#sendVerCodePage").hide();
                $("#changeNaIPage").show();
                getExpertInfo();
            }
        };
        hashChange();

        //点击【发送】
        $("#btnSend").click(function () {

            phoneNum = $.trim($("#txtPhone").val());
            if (phoneNum == "") {
                $.ligerDialog.warn("请输入手机号码");
                return;
            } else if (!validitor.phone(phoneNum)) {
                $.ligerDialog.warn("请输入正确的手机号码");
                return;
            } else {
                $.get("../Handlers/ExpertAccountHandler.ashx", { func: "getvercode", funccode: "expertNaIdreset", checkPhoneExists: true, phone: phoneNum, stamp: new Date() - 0 }, function (rst) {
                    if (!rst.Success) {
                        $.ligerDialog.error(rst.Msg);
                    }
                }, "json");
                PhoneSendTimer($("#btnSend"), 60);
            }
        });

        /**
        *发送手机号码的计时器
        *obj 按钮
        *time 倒计时时限
        */
        function PhoneSendTimer(obj, time) {
            if (!obj) return;
            obj = $(obj);
            time = time || 60;
            var oriText = obj.val();

            obj.attr("disabled", "disabled").addClass("disabled");

            (function f() {
                if (time-- <= 0) {
                    obj.removeAttr("disabled").removeClass("disabled");
                    obj.val(oriText);
                    return;
                }
                setTimeout(function () {
                    obj.val(time + "秒后可重新发送");
                    f();
                }, 1000);
            } ())
        }

        //点击【确认】
        $("#btnToChangePwd").click(function () {
            phoneNum = $.trim($("#txtPhone").val());
            if (phoneNum == "") {
                $.ligerDialog.warn("请输入手机号码");
                return;
            } else if (!validitor.phone(phoneNum)) {
                $.ligerDialog.warn("请输入正确的手机号码");
                return;
            }
            verCode = $.trim($("#txtVerCode").val());
            if (!validitor.vercode(verCode)) {
                $.ligerDialog.warn("请输入正确的验证码");
                return;
            }
            $.get("../Handlers/ExpertAccountHandler.ashx", { func: "checkvercode", funccode: "expertNaIdreset", phone: phoneNum, vercode: verCode, "rand": Math.random() }, function (rst) {

                //// success:验证码正确 incorrent验证码错误 overcount超出当天规定次数
                switch (rst.result) {
                    case "success":
                        hashChange("#changeNaIPage");
                       $("#<%= hidmobile.ClientID%>").val(rst.value);
                        getExpertInfo();
                        break;
                    case "incorrent":
                        $.ligerDialog.warn("验证码不正确，或已经超过时限");
                        break;
                    case "overcount":
                        $.ligerDialog.warn("今天发送验证码已经达到三次，请明天再试。");
                        break;
                    default: break;
                }
            }, "json");
        });

        function getExpertInfo() {
            var mobile = $("#<%=hidmobile.ClientID%>").val();
            if (!mobile) return;
            $.get("../Handlers/ExpertAccountHandler.ashx", { func: "getExpertInfo", phone: mobile, "rand": Math.random() }, function (data) {
                if (data.result == true) {
                    $("#name").val(data.name);
                    $("#idnum").val(data.idcard);
                }
            }, "json");
        }

        $("#btnChangNaI").click(function () {
            var mobile = $.trim($("#<%= hidmobile.ClientID%>").val());
            if (!mobile) {
                $.ligerDialog.warn("操作无效");
                return;
            }
            var name = $.trim($("#name").val());
            if (!name) {
                $.ligerDialog.warn("请输入姓名");
                return;
            }
            var idcard = $.trim($("#idnum").val());
            if (!idcard) {
                $.ligerDialog.warn("请输入身份证号码");
                return;
            }
            if (!validitor.idcard(idcard)) {
                $.ligerDialog.warn("身份证号码格式不正确");
                return false;
            }
            $.post("../Handlers/ExpertAccountHandler.ashx", { func: "changeNaI", mobile: mobile, name: name, idcard: idcard, "rand": Math.random() }, function (rst) {
                if (rst.ret) {
                    getExpertInfo();
                    $.ligerDialog.alert(rst.msg);
                } else {
                    $.ligerDialog.alert(rst.msg);
                }
            }, "json");
        });

        $("#edtname").click(function () {
            $("#name").removeAttr("disabled");
        });

        $("#edtid").click(function () {
            $("#idnum").removeAttr("disabled");
        });
    </script>
</body>
</html>
